@page
@inherits Payment.Web.Pages.PaymentPageBase
@using EventHub.Organizations
@using EventHub.Web.Pages.Organizations
@using EventHub.Web.Pages.Payment
@using Microsoft.AspNetCore.Http
@using Newtonsoft.Json
@using Payment.Web.Pages.Payment
@model Payment.Web.Pages.Payment.PreCheckoutPageModel
@inject IOrganizationAppService OrganizationAppService

@{
    var isExistExtraProperties = Model.PaymentRequest.ExtraProperties.TryGetValue(nameof(OrganizationPaymentRequestExtraParameterConfiguration), out var ExtraProperties);
    if (!isExistExtraProperties)
    {
        throw new BadHttpRequestException("");
    }
    
    var organizationPaymentRequestExtraParameterConfiguration = JsonConvert.DeserializeObject<OrganizationPaymentRequestExtraParameterConfiguration>(ExtraProperties.ToString());
    if (organizationPaymentRequestExtraParameterConfiguration is null)
    {
        throw new BadHttpRequestException("");
    }
    var organizationName = organizationPaymentRequestExtraParameterConfiguration.OrganizationName;
    var planInfo = PlanInfoHelper.GetPlan(organizationPaymentRequestExtraParameterConfiguration.TargetPlanType, await OrganizationAppService.GetPlanInfosAsync());

}
@section scripts {
    <abp-script-bundle name="@typeof(PreCheckoutPageModel).FullName">
        <abp-script src="/client-proxies/Payment-proxy.js" />
    </abp-script-bundle>
}
<main class="static-page container mt-5"> 
    <h1 class="text-center mb-3">Shopping Cart</h1> 
    <div class="row"> 
        <div class="col-md-7">
            <div class="card">
                <div class="card-body px-5 py-4"> 
                    <h2 class="my-4">Product Detail</h2>
                    <h3 class="my-4">@OrganizationPlanType.Premium Account: <span class="text-primary">@organizationName.ToUpperInvariant()</span></h3>
                    @if (!organizationPaymentRequestExtraParameterConfiguration.IsExtend && planInfo.IsExtendable)
                    {
                        <p>Start Date: <span class="text-dark">@DateTime.Now.ToShortDateString()</span></p>
                        <p>End Date: <span class="text-dark">@DateTime.Now.AddMonths(planInfo.OnePaidEnrollmentPeriodAsMonth!.Value).ToShortDateString()</span></p>
                    }
                    else
                    {
                        <p>Your license will be extended for  <span class="text-dark">@planInfo.OnePaidEnrollmentPeriodAsMonth!.Value</span> months.</p>
                    }
                </div> 
            </div> 
        </div>
        <div class="col-md-5">
            <div class="card">
                <div class="card-body px-5 py-4"> 
                    <h2 class="mt-4">Summary</h2> 
                    <div class="cart-summary pt-3 pb-2">
                        <p class="my-4">Premium Licence <span class="text-dark float-end">@Model.PaymentRequest.Price @Model.PaymentRequest.Currency</span></p>
                        <hr>
                        <p class="my-4">TOTAL <span class="text-dark float-end">@Model.PaymentRequest.Price @Model.PaymentRequest.Currency</span></p> 
                    </div>
                    <form method="post">
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-info my-4">@L["Checkout"]</button>
                        </div>
                    </form>
                </div> 
            </div> 
        </div>  
    </div>
</main>
